package com.socket;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author Yancy
 * @program springioctest
 * @create 2021-01-17
 */
public class TestURL {
  public static void main(String[] args) throws MalformedURLException {
    //

//    URL url = new URL("https://www.bjsxt.com/news/11002.html#abc");
      URL url = new URL("https://www.bjsxt.com/news/11002.html?userName=张三");

      // 协议
    System.out.println(url.getProtocol());
    // ip
    System.out.println(url.getHost());
    // 端口
    System.out.println(url.getPort());

    // 默认端口 http 80  https 443
    System.out.println(url.getDefaultPort());

    //      /news/11002.html
    System.out.println(url.getPath());

    //锚节点 #abc
    System.out.println(url.getRef());

    // 用户信息
    System.out.println(url.getQuery());
  }
}
